import typescript from 'rollup-plugin-typescript2';
import vue from 'rollup-plugin-vue';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import scss from 'rollup-plugin-scss';
import babel from '@rollup/plugin-babel';

export default {
  input: 'src/index.ts',
  output: [
    {
      file: 'dist/medical-editor.cjs.js',
      format: 'cjs'
    },
    {
      file: 'dist/medical-editor.esm.js',
      format: 'es'
    },
    {
      file: 'dist/medical-editor.umd.js',
      format: 'umd',
      name: 'MedicalEditor'
    }
  ],
  plugins: [
    vue({
      target: 'browser',
      css: true,
      compileTemplate: true,
      template: {
        isProduction: true,
        compilerOptions: {
          whitespace: 'condense'
        }
      }
    }),
    typescript({
      tsconfig: './tsconfig.json',
      useTsconfigDeclarationDir: true,
      clean: true,
      tsconfigOverride: {
        compilerOptions: {
          module: 'ESNext',
          skipLibCheck: true
        }
      }
    }),
    resolve({
      extensions: ['.js', '.ts', '.vue'],
      dedupe: ['vue', 'slate-vue']
    }),
    commonjs(),
    scss({
      output: 'dist/medical-editor.css'
    }),
    terser(),
    babel({
      babelHelpers: 'runtime',
      extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'],
      exclude: 'node_modules/**', 
      presets: [
        ['@babel/preset-env', { modules: false }],
        '@babel/preset-typescript'
      ],
      plugins: [
        '@babel/plugin-transform-runtime',
        '@babel/plugin-transform-typescript',
        '@vue/babel-plugin-jsx'
      ]
    }),
  ],
  external: ['vue', 'pinia', 'slate', 'slate-react']
};